<?php

$dbhost = "localhost";
$dbuser = "root";
$dbpassword = "";

$database = "ThreadExtraction";
$dataTable = "Data";
$annotationsTable = "Annotations";
$fileTable = "Files";

$page = $_GET['page']; // get the requested page 
$limit = $_GET['rows']; // get how many rows we want to have into the grid 
$sidx = $_GET['sidx']; // get index row - i.e. user click to sort 
$sord = $_GET['sord']; // get the direction 
$filenumber = $_GET['file'];
$thread = $_GET['thread'];
$annotator = $_GET['annotator'];

//$filenumber = 1;

//$thread = 1;

//$annotator = 1;

if(!$sidx) $sidx =1; 

// connect to the database 
$db = mysql_connect($dbhost, $dbuser, $dbpassword) or die("Connection Error: " . mysql_error()); 
mysql_select_db($database) or die("Error conecting to db."); 

$dataSql = "select d.postnum as postid, timestamp, user, content, parent, relation from data d, annotations a where filenumber=$filenumber and d.id = a.postid and a.thread=$thread and a.annotator=$annotator ORDER BY 1";

$data = mysql_query($dataSql) or die("Couldn't execute data query.".mysql_error()); 

$response->records = $count; 
$response->page = $page; $response->total = $total_pages; 
$i=0; 

while($row = mysql_fetch_array($data, MYSQL_ASSOC)) { 
//        print_r($hash);
//        print_r($row);
	$response->rows[$i]['id']=$row[postid]."-".$annotator;
	$response->rows[$i]['cell']=array($row[postid], $row[timestamp], $row[user], $row[content], $row[parent], $row[relation]);
	$i++; 
} 

echo json_encode($response);
?>
